package nodos;

import java.util.ArrayList;

import javax.swing.tree.DefaultMutableTreeNode;

import mundo.SimboloLexico;

public class NodoListaInterfaces extends Nodo {

	private SimboloLexico identificador;
	private NodoListaInterfaces listaInterfaces;

	public NodoListaInterfaces(SimboloLexico identificador, NodoListaInterfaces listaInterfaces) {
		this.identificador = identificador;
		this.listaInterfaces = listaInterfaces;
	}

	@Override
	public DefaultMutableTreeNode getSubArbolVisual() {
		DefaultMutableTreeNode raiz=new DefaultMutableTreeNode("Lista de Interfaces");
		raiz.add(new DefaultMutableTreeNode(identificador.getLexema()));
		ArrayList<String> interfaces=obtenerInterfaces();
		if(interfaces.size()!=0)
			for (String interfaz : interfaces) {
				raiz.add(new DefaultMutableTreeNode(interfaz));
			}
		return raiz;
	}

	private ArrayList<String> obtenerInterfaces(){
		ArrayList<String> interfaces=new ArrayList<String>();
		guardarInterfaces(interfaces, listaInterfaces);
		return interfaces;
	}
	private void guardarInterfaces(ArrayList<String> interfaces,NodoListaInterfaces raizSubArbol){
		if(raizSubArbol==null)
			return;
		else{
			interfaces.add(raizSubArbol.identificador.getLexema());
			guardarInterfaces(interfaces, raizSubArbol.listaInterfaces);
		}
	}

	@Override
	public String traducir(int profundidad) {
		String codJava=identificador.traducirSimbolo();
		if(listaInterfaces!=null)
			codJava+=","+listaInterfaces.traducir(profundidad);
		return codJava;
	}

}
